# -*- coding: utf-8 -*-

# Define your item clonestart here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
import pymysql


class XiechengPipeline(object):
    def __init__(self):
        self.connect = pymysql.connect(
            host='47.99.207.109',
            port=3306,
            user='root',
            password='123456',
            db='assetSpider',
            charset='utf8'
        )
        self.cursor = self.connect.cursor()

    def process_item(self, item, spider):
        sql = """insert into asp_hotels_list(
        hotel_orgid, hotel_name, 
        hotel_address, hotel_score, hotel_stardesc, 
        hotel_img, hotel_dpscore, hotel_dpcount, hotel_star, 
        hotel_shortName, hotel_deturl, hotel_lat, hotel_lon, 
        create_time, hotel_area) VALUES 
        (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,now(),%s)"""
        val = (item['hotel_orgid'], item['hotel_name'],
               item['hotel_address'], item['hotel_score'],item['hotel_stardesc'],
               item['hotel_img'],item['hotel_dpscore'],item['hotel_dpcount'],item['hotel_star'],
               item['hotel_shortName'],item['hotel_deturl'],item['hotel_lat'],item['hotel_lon'],item['hotel_area'])
        self.cursor.execute(sql, val)
        self.connect.commit()
        return item
